/*************************************************************************
	> File Name: user.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年11月29日 星期一 22时14分30秒
 ************************************************************************/

#include<iostream>
#include <string>
#include <utility>

class User
{
public:
	User() = default;
	User(int id, std::string n) : _id(id), name(n) {}

	void setId(int value)
	{
		_id = value;
	}

	int getId()
	{
		return _id;
	}

	void setName(std::string n)
	{
		name = n;
	}

	std::string getName()
	{
		return name;
	}

private:
	int _id;
	std::string name;
};

class Department
{
public:
	Department() = default;
	Department(int id, std::string n) : _id(id), name(n) {}

	void setId(int value)
	{
		_id = value;
	}

	int getId()
	{
		return _id;
	}

	void setName(std::string n)
	{
		name = n;
	}

	std::string getName()
	{
		return name;
	}

private:
	int _id;
	std::string name;
};

//抽象类
struct IUser
{
	virtual void insert(User user) = 0;
	virtual User getUser(int value) = 0;
};

struct SqlserverUser : public IUser
{
	virtual void insert(User user)
	{
		std::cout << "在SQL Server中在User表中插入一条记录" << std::endl;
	}

	virtual User getUser(int value)
	{
		std::cout << "在SQL Server中根据ID在User表中查询一条记录" << std::endl;
		return User();
	}
};

struct AccessUser : public IUser
{
	virtual void insert(User user)
	{
		std::cout << "在Access中在User表中插入一条记录" << std::endl;
	}

	virtual User getUser(int value)
	{
		std::cout << "在Access中根据ID在User表中查询一条记录" << std::endl;
		return User();
	}
};

struct IDepartment
{
	virtual void insert(Department dept) = 0;
	virtual Department getDepartment(int value) = 0;
};

struct SqlserverDepartment : public IDepartment
{
	virtual void insert(Department dept)
	{
		std::cout << "在SQL Server中在Department表中插入一条记录" << std::endl;
	}
	
	virtual Department getDepartment(int value)
	{
		std::cout << "在SQL Server中根据ID在Department表中查询一条记录" << std::endl;
		return Department();
	}
};

struct AccessDepartment : public IDepartment
{
	virtual void insert(Department dept)
	{
		std::cout << "在Access中在Department表中插入一条记录" << std::endl;
	}

	virtual Department getDepartment(int value)
	{
		std::cout << "在Access中根据ID在Department表中查询一条记录" << std::endl;
		return Department();
	}
};


class DataAccess
{
public:
	DataAccess()
	{
		p = std::make_pair("Sqlserver", 1);
	}

	DataAccess(std::string s, int value)
	{
		p = std::make_pair(s, value);
	}

	IUser* createUser()
	{
		IUser* result;
		switch (p.second)
		{
			case 1:
				result = new SqlserverUser();
				break;
			case 2:
				result = new AccessUser();
				break;
		}
		return result;
	}

	IDepartment* createDepartment()
	{
		IDepartment* dept;
		switch (p.second)
		{
			case 1:
				dept = new SqlserverDepartment();
				break;
			case 2:
				dept = new AccessDepartment();
				break;
		}
		return dept;
	}

private:
	std::pair<std::string, int> p;
};
